﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ElectronicCommerce.Framework.Web.Mvc
{
    public class CustomModelContainer<TCustomContext> where TCustomContext : CustomContextBase
    {
        private CustomModelDictionary _modelDic = null;
        public CustomModelContainer(TCustomContext customContext, CustomModelDictionary modelDic)
        {
            _modelDic = modelDic;
            CustomContext = customContext;
        }

        public CustomModelDictionary ModelDictionary
        {
            get
            {
                return _modelDic;
            }
        }

        public TCustomContext CustomContext
        {
            get;
            private set;
        }
    }

    public class CustomModelContainer<TCustomContext, TModel> : CustomModelContainer<TCustomContext>
        where TCustomContext : CustomContextBase
        where TModel : CustomModelBase
    {
        private TModel _currentModel = null;

        public CustomModelContainer(TCustomContext customContext, CustomModelDictionary modelDic)
            : base(customContext, modelDic) { }

        public TModel Current
        {
            get
            {
                if (_currentModel == null)
                {
                    _currentModel = ModelDictionary.Get<TModel>();
                }
                return _currentModel;
            }
        }
    }
}
